package com.ming.spring.controller;

import com.ming.spring.annotation.HAutowired;
import com.ming.spring.annotation.HController;
import com.ming.spring.annotation.HRequestMapping;
import com.ming.spring.service.UserService;
import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@HController
@HRequestMapping("/user")
public class UserController {
    @HAutowired
    public UserService userService;

    @HRequestMapping("/get")
    public void getUserName(HttpServletRequest req, HttpServletResponse resp){
        if(StringUtils.isEmpty(req.getParameter("username"))){
            try {
                resp.getWriter().write("param username is empty");
            } catch (IOException e) {
                e.printStackTrace();
            }
        }else{
            String username = req.getParameter("username");
            try {
                resp.getWriter().write("param username is "+username);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    @HRequestMapping("/list")
    public void listClassName(HttpServletRequest req,HttpServletResponse resp){
        try {
            resp.getWriter().write(userService.getUserName());
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
